package com.test.design.pattern.interpreter;

/**
 * @ClasName Variable
 * @Descripution TODO
 * @Author USER
 * @Date 2022/2/26 11:13
 * @Version V1.0
 */
public class Variable extends AbstractExpression {

    //声明存储变量名的成员变量
    private String name;

    public Variable(String name) {
        this.name = name;
    }

    public int interpret(Context context) {
        //直接返回变量的值
        return context.getValue(this);
    }

    @Override
    public String toString() {
        return name;
    }
}
